<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="供应商" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'supplierName', validatorRules.supplierName]" placeholder="请输入供应商"></a-input>
        </a-form-item>
        <a-form-item label="采集时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择采集时间" v-decorator="[ 'acqTime', validatorRules.acqTime]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="原材料库房" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'rawMatPlace', validatorRules.rawMatPlace]" placeholder="请输入原材料库房"></a-input>
        </a-form-item>
        <a-form-item label="温度" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'rawMatTemp', validatorRules.rawMatTemp]" placeholder="请输入温度" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="湿度" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'rawMatHum', validatorRules.rawMatHum]" placeholder="请输入湿度" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="smt表面贴装" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'smtPlace', validatorRules.smtPlace]" placeholder="请输入smt表面贴装"></a-input>
        </a-form-item>
        <a-form-item label="温度" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'smTemp', validatorRules.smTemp]" placeholder="请输入温度" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="湿度" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'smtHum', validatorRules.smtHum]" placeholder="请输入湿度" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="波峰焊" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'waveSDolPlace', validatorRules.waveSDolPlace]" placeholder="请输入波峰焊"></a-input>
        </a-form-item>
        <a-form-item label="温度" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'waveSDolTemp', validatorRules.waveSDolTemp]" placeholder="请输入温度" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="湿度" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'waveSDolHum', validatorRules.waveSDolHum]" placeholder="请输入湿度" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="板卡检测" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'boardTestPlace', validatorRules.boardTestPlace]" placeholder="请输入板卡检测"></a-input>
        </a-form-item>
        <a-form-item label="温度" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'boardTestTemp', validatorRules.boardTestTemp]" placeholder="请输入温度" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="湿度" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'boardTestHum', validatorRules.boardTestHum]" placeholder="请输入湿度" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="板卡库房" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'boardHousePlace', validatorRules.boardHousePlace]" placeholder="请输入板卡库房"></a-input>
        </a-form-item>
        <a-form-item label="温度" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'boardHouseTemp', validatorRules.boardHouseTemp]" placeholder="请输入温度" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="湿度" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'boardHouseHum', validatorRules.boardHouseHum]" placeholder="请输入湿度" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="装置生产" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'plantProPlace', validatorRules.plantProPlace]" placeholder="请输入装置生产"></a-input>
        </a-form-item>
        <a-form-item label="温度" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'plantProTemp', validatorRules.plantProTemp]" placeholder="请输入温度" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="湿度" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'plantProHum', validatorRules.plantProHum]" placeholder="请输入湿度" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="工厂" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'factory', validatorRules.factory]" placeholder="请输入工厂"></a-input>
        </a-form-item>
        
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'  
  
  export default {
    name: "ZxjEip2chjwsdModal",
    components: { 
      JDate,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
          supplierName:{rules: [{ required: true, message: '请输入供应商!' }]},
          acqTime:{rules: [{ required: true, message: '请输入采集时间!' }]},
          rawMatPlace:{},
          rawMatTemp:{rules: [{ required: true, message: '请输入温度!' }]},
          rawMatHum:{rules: [{ required: true, message: '请输入湿度!' }]},
          smtPlace:{},
          smTemp:{rules: [{ required: true, message: '请输入温度!' }]},
          smtHum:{rules: [{ required: true, message: '请输入湿度!' }]},
          waveSDolPlace:{},
          waveSDolTemp:{rules: [{ required: true, message: '请输入温度!' }]},
          waveSDolHum:{rules: [{ required: true, message: '请输入湿度!' }]},
          boardTestPlace:{},
          boardTestTemp:{rules: [{ required: true, message: '请输入温度!' }]},
          boardTestHum:{rules: [{ required: true, message: '请输入湿度!' }]},
          boardHousePlace:{},
          boardHouseTemp:{rules: [{ required: true, message: '请输入温度!' }]},
          boardHouseHum:{rules: [{ required: true, message: '请输入湿度!' }]},
          plantProPlace:{},
          plantProTemp:{rules: [{ required: true, message: '请输入温度!' }]},
          plantProHum:{rules: [{ required: true, message: '请输入湿度!' }]},
        factory:{},
        },
        url: {
          add: "/zxjEip2chjwsd/zxjEip2chjwsd/add",
          edit: "/zxjEip2chjwsd/zxjEip2chjwsd/edit",
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'supplier','collecttimw','yclkf','yclkfWd','yclkfSd','smt','smtWd','smtSd','bfh','bfhWd','bfhSd','bkjc','bkjcWd','bkjcSd','bkkf','bkkfWd','bkkfSd','zzsc','zzscWd','zzscSd','factory','supplierCode','processRouteNo','ioflag','updateTime'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'supplier','collecttimw','yclkf','yclkfWd','yclkfSd','smt','smtWd','smtSd','bfh','bfhWd','bfhSd','bkjc','bkjcWd','bkjcSd','bkkf','bkkfWd','bkkfSd','zzsc','zzscWd','zzscSd','factory','supplierCode','processRouteNo','ioflag','updateTime'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>